package com.jiot.controller.device;

import com.zg.cloud.BaseResponse;
import com.zg.cloud.CommonEnum;
import com.zg.cloud.annotation.RoleCheck;
import com.zg.cloud.annotation.TokenCheck;
import com.zg.cloud.service.DeviceFunctionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import req.functional.inspect.GenerateInspectionReq;
import req.functional.inspect.GetInspectionTitleInfoReq;
import req.functional.inspect.GetListReq;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author liling
 * @date 2020/11/19 15:57
 * @description
 **/
@RestController
@RequestMapping("/device/functional")
@Api(value = "职能端用户模块")
public class DeviceFunctionalController {

    @Resource
    private DeviceFunctionService deviceFunctionService;

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/device/count")
    @TokenCheck
    @ApiOperation(value = "设备数量", notes = "device")
    public BaseResponse deviceCount() {
        return new BaseResponse(deviceFunctionService.deviceCount());
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/status/count")
    @TokenCheck
    @ApiOperation(value = "各状态设备数量", notes = "device")
    public BaseResponse statusCount() {
        return new BaseResponse(deviceFunctionService.countByAreaAndStatus());
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/inspection")
    @TokenCheck
    @ApiOperation(value = "用户巡检", notes = "device")
    public BaseResponse inspection() {
        return new BaseResponse(deviceFunctionService.inspection());
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/inspection/notice")
    @TokenCheck
    @ApiOperation(value = "巡检一键通知", notes = "device")
    public BaseResponse inspectionNotice(@RequestBody @Valid GenerateInspectionReq generateInspectionReq) {
        return new BaseResponse(deviceFunctionService.inspectionNotice(generateInspectionReq));
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/last/inspection")
    @TokenCheck
    @ApiOperation(value = "上次巡检信息", notes = "device")
    public BaseResponse lastInspection() {
        return new BaseResponse(deviceFunctionService.lastInspectionInfo());
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/inspection/list")
    @TokenCheck
    @ApiOperation(value = "巡检台账", notes = "device")
    public BaseResponse inspectionList(@RequestBody @Valid GetListReq getListReq) {
        return new BaseResponse(deviceFunctionService.inspectionList(getListReq));
    }

    @RoleCheck({CommonEnum.Role.FUNCTIONAL})
    @PostMapping("/inspection/title/info")
    @TokenCheck
    @ApiOperation(value = "台账页面顶部信息", notes = "device")
    public BaseResponse inspectionTitleInfo(@RequestBody @Valid GetInspectionTitleInfoReq getInspectionTitleInfoReq) {
        return new BaseResponse(deviceFunctionService.inspectionTitleInfo(getInspectionTitleInfoReq));
    }
}
